Optical pattern recognition